//
//  BanBu_ImageView.m
//  BanBu
//
//  Created by banbu3 on 7/22/13.
//
//
#import "BanBu_ImageView.h"
#import "BanBu_ThemeManager.h"
@implementation BanBu_ImageView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

    }
    return self;
}
-(void)changeTheme
{
    if(self)
    {
        switch (imageType) {
            case UIImageViewCreatTypeCell:
                self.image = [[ThemeManager getThemeImage:@"tablecell_backimage.png"]stretchableImageWithLeftCapWidth:15.0 topCapHeight:15.0];
                if(!self.image&&_imageName.length)
                {
                    self.image = [[UIImage imageNamed:_imageName] stretchableImageWithLeftCapWidth:2.0 topCapHeight:4.0];
                }
                break;
            case UIImageViewCreatTypeTable:
                self.image = [ThemeManager getThemeImage:@"table_backimage.jpg"];
                if(!self.image&&_imageName.length)
                {
                    self.image = [[UIImage imageNamed:_imageName] stretchableImageWithLeftCapWidth:2.0 topCapHeight:4.0];
                }
                break;
            case UIImageViewCreatTypeChat:
                self.image = [ThemeManager getThemeImage:@"chatbar.png"];
                if(!self.image&&_imageName.length)
                {
                    self.image = [[UIImage imageNamed:_imageName]stretchableImageWithLeftCapWidth:12.0 topCapHeight:4.0];
                }
                break;
            case UIImageViewCreatTypeFoot:
                self.image = [ThemeManager getThemeImage:@"tablefoot.png"];
                if(!self.image&&_imageName.length)
                {
                    self.image = [[UIImage imageNamed:_imageName]stretchableImageWithLeftCapWidth:2.0 topCapHeight:4.0];
                }
                break;
            case UIImageViewCreatTypeOther:
                self.image = [ThemeManager getThemeImage:_imageName];
                if(!self.image&&_imageName.length)
                {
                    self.image = [[UIImage imageNamed:_imageName]stretchableImageWithLeftCapWidth:2.0 topCapHeight:4.0];
                }
            default:
                break;
        }
    }
}
-(id)initWithBackGroundImageType:(BackGroundImageCreatType)Type;
{
    if(self = [super init])
    {
        _imageName = [[NSMutableString alloc] init];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme) name:kThemeDidChangeNotification object:nil];
        imageType = Type;
        [self changeTheme];
    }
    return self;
}
-(id)initWithBackGroundImageType:(BackGroundImageCreatType)Type imageName:(NSString *)_name;
{
    if(self = [super init])
    {
        if(_name.length)
        _imageName = [[NSMutableString alloc] initWithString:_name];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme) name:kThemeDidChangeNotification object:nil];
        imageType = Type;
        [self changeTheme];
    }
    return self;

}
-(id)initWithBackGroundImageName:(NSString *)_name;
{
    if(self = [super init])
    {
        if(_name.length)
            _imageName = [[NSMutableString alloc] initWithString:_name];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme) name:kThemeDidChangeNotification object:nil];
        imageType = UIImageViewCreatTypeOther;
        [self changeTheme];
    }
    return self;
}

-(void)dealloc
{
    [super dealloc];
    [_imageName release],_imageName = nil;
    [[NSNotificationCenter defaultCenter]removeObserver:self name:kThemeDidChangeNotification object:nil];
}
@end
